/**
* Project Name:myservice
* Date:2018年12月16日
* Copyright (c) 2018, jingma All Rights Reserved.
*/

package cn.benma666.kettle.ljq;

import cn.benma666.iframe.Result;
import cn.benma666.kettle.domain.VJob;
import cn.benma666.kettle.mytuils.TimingUtil;
import com.alibaba.fastjson.JSONObject;
import org.pentaho.di.core.exception.KettleException;

/**
 * 作业定时设置拦截器 <br/>
 * date: 2018年12月16日 <br/>
 * @author jingma
 * @version 0.1
 */
public class JobDsszLjq extends KettleLjq {
    @Override
    public JSONObject jcxx(JSONObject myParams) {
        Integer idJob = myParams.getIntValue("$.yobj.id_job");
        myParams.set("$.cllxkz."+getCllx(myParams)+".putobj",false);
        myParams = super.jcxx(myParams);
        //取出对应作业的定时信息
        JSONObject timing = TimingUtil.getTimingByJobId(new VJob(myParams.getString("$.yobj.zyk"),idJob));
        timing.put("id_job", idJob);
        timing.put("zyk",myParams.getString("$.yobj.zyk"));
        myParams.put(KEY_OBJ, timing);
        return myParams;
    }
    @Override
    public Result save(JSONObject myParams) {
        JSONObject timing = myParams.getJSONObject(KEY_YOBJ);
        try {
            TimingUtil.saveTimingToKettle(new VJob(timing.getString("zyk"),timing
                    .getIntValue("id_job")),timing);
            return success("保存成功");
        } catch (KettleException e) {
            return failed("报错定时信息失败："+e.getMessage(),e);
        }
    }
}
